/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : ScreenSaver.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "ScreenSaverEvent.h"
#include "./win/NetmenuSetupEvent.h"
void SetScrSaverPalette_720P(void)
{
    YUVENTRY mask_para[4] = {0,4095,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 16392,0x8000 | 16408,0x8000 | 16408,16424,16424,16440,16440,16456,16456,16472,16472,16488,16488,16504,16504};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetScrSaverPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
        case OsdSize720p:
            RECT StandardWindowRect = {276,158,226,158};
            pControl->winrect = StandardWindowRect;
            CREATEWINDOWPARAM StandardWindowPara = {1,{{276,158,226,158},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetScrSaverPalette_720P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&StandardWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlScrSaver_720P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
        case OsdSize720p:
            CREATEWINDOWPARAM Standardwindow_para = {1,{{276,158,226,158},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetScrSaverPalette_720P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","ScrSaver",WS_OVERLAPPEDWINDOW,
		                      276,158,226,158,NULL, (INT32S)&Standardwindow_para,NULL) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetScrSvrPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){	
        case OsdSize720p:
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 226;
            pControl->winrect.height = 158;
            pControl->draw_info_num = 1;
            RECT StandardDrawRect[1] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,226,158},
            };
            for(iLoop=0; iLoop < 1; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S ScrSvrMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_KEYDOWN:
            return ScrSvrOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlScrSvr_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- ScrSvr
    HWND *pNewControl;
    switch(CurOsdSize){
        case OsdSize720p:
            pNewControl = AWCreateWinControl("TControl","ScrSvr",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,226,158,pParent,0,ScrSvrMsgProc_720P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 1;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO StandardDrawDatas[1] = {
                          {0,0,0,0,(INT32U)ICON_SCREEN_SAVE,DT_RLE_BMP_DATA}};
            memcpy(pNewControl->draw_info,StandardDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND *CreateMenuScrSaver_720P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pScrSaver = CreateControlScrSaver_720P(NULL,CurrentOsdSize);
    SetScrSaverPos_720P(pScrSaver,CurrentOsdSize);

    pNewControl= CreateControlScrSvr_720P(pScrSaver,CurrentOsdSize);
    SetScrSvrPos_720P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pScrSaver;
    pWin->pFocusControl = AWFindWinCtrlByName("ScrSvr");
    return pScrSaver;
}

void WinResetScrSaverControlsPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://ScrSaver
            SetScrSaverPos_720P(pControl,CurOsdSize) ;
            break ;
        case 1://ScrSvr
            SetScrSvrPos_720P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetScrSaverPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("ScrSaver");
    if(pControl == NULL) return ;

    WinResetScrSaverControlsPos_720P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetScrSaverPos_720P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

